package yuhuibear.poat.object.mapEntity;

import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import yuhuibear.poat.object.bean.BeanStruct;

public abstract class SqlTask implements MapEntityTask {

	private static int totalCnt = 0;

	protected static Log log = LogFactory.getLog(SqlTask.class);

	private String name;

	private Type type;

	private BeanStruct struct;

	private String defPlace;

	private String sql;

	private String error;

	protected boolean done = false;

	public SqlTask() {}

	protected Set<String> refs = new LinkedHashSet<String>();

	public Set<String> getReferences() {
		return refs;
	}

	public boolean isDone() {
		return done;
	}

	protected static void register() {
		totalCnt++;
	}

	protected static void unRegister() {
		totalCnt--;
	}

	public static int getTotalCnt() {
		return totalCnt;
	}

	protected void init(String name, Type type, String defPlace,
			BeanStruct bean, String sql) {
		this.struct = bean;
		this.name = name;
		this.defPlace = defPlace;
		this.type = type;
		this.sql = sql;
	}

	public final BeanStruct getStruct() {
		return struct;
	}

	public String getName() {
		return name;
	}

	public Type getType() {
		return type;
	}

	public String getDefPlace() {
		return defPlace;
	}

	public String getSql() {
		return sql;
	}

	public void setStruct(BeanStruct struct) {
		this.struct = struct;
	}

	public String getDefinePlace() {
		return this.defPlace;
	}

	public String getError() {
		return error == null ? "" : error;
	}

	public void setError(String error) {
		this.error = error;
	}

	public String toString() {
		return String.format("class: %s, [name:%s, type:%s, sql:%s, %s]", defPlace, name, type, sql, error);
	}
}
